package chant.controller;

import chant.model.Area;
import chant.model.Book;
import chant.model.Chant;
import chant.util.AreaUtil;
import chant.util.BookUtil;
import com.jfinal.core.Controller;

import java.util.Date;
import java.util.List;

/**
 * Create-Date: 2016/6/16
 * Description:
 */
public class IndexController extends Controller {

    public void index() {
        List<Area> provinceList = AreaUtil.getProvinceList();
        List<Area> cityList = AreaUtil.getCityList(provinceList.get(0).getInt("id"));
        List<Book> bookList = BookUtil.getBookList();

        setAttr("bookList", bookList);
        setAttr("provinceList", provinceList);
        setAttr("cityList", cityList);
        render("index.html");
    }

    public void getCities() {
        int pid = getParaToInt("pid");
        List<Area> cityList = AreaUtil.getCityList(pid);
        renderJson(cityList);
    }

    public void collect() {
        Chant chant = getModel(Chant.class);
        chant.set("submit_time", new Date());
        chant.save();
        setAttr("res", "success");
        render("result.html");
    }
}
